<?php

namespace App\Http\Controllers\Api;

use App\Support\Response;
//use App\Support\TransformerResponse;
//use League\Fractal\Manager;
use App\Http\Controllers\Controller;

class ApiController extends Controller
{
//    protected $response;
//
//    /**
//     * ApiController constructor.
//     */
//    public function __construct()
//    {
//        $manager = new Manager();
//
//        $this->response = new Response(response(), new TransformerResponse($manager));
//    }

    /**
     * @return Response
     */
    public function response(){
        return app(Response::class);
    }

    /**
     * 分页时每页显示多少数据
     *
     * @return int
     */
    public function perPage($default = null)
    {
        $maxPerPage = 40;
        if (method_exists($this, 'defaultPerPage'))
            $perPage = (request('per_page') ?: $default) ?: $this->defaultPerPage();
        return (int)($perPage < $maxPerPage ? $perPage : $maxPerPage);
    }

    public function defaultPerPage()
    {
        return 20;
    }

}
